package com.payment.controller.paynotify;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.payment.entity.agatewaytobeijing.JsonConstant;
import com.payment.entity.agatewaytobeijing.end.response.EndResponse;
import com.payment.entity.agatewaytobeijing.order.RequestPurchaseService;
import com.payment.entity.agatewaytobeijing.order.response.OrderResponse;
import com.payment.entity.agatewaytobeijing.querydeviceorder.response.DevicePackageOrder;
import com.payment.entity.agatewaytobeijing.querydeviceorder.response.ResponseQueryDeviceOrder;
import com.payment.entity.common.OrderPaymentManager;
import com.payment.entity.common.UserboundPaymentOrder;
import com.payment.entity.newrequestnotify.request.RequestNotify;
import com.payment.entity.newrequestnotify.response.ResponseNotify;
import com.payment.entity.payresults.PaypalNotificationpaymentResults;
import com.payment.entity.payresults.PaypalpaymentResults;
import com.payment.entity.payresults.paypal.*;
import com.payment.service.NotificationpaymentService;
import com.payment.service.OrderPaymentManagerService;
import com.payment.service.PartnerService;
import com.payment.service.agatewaytobeijing.GatewayToBeijingService;
import com.payment.utils.Constant;
import com.payment.utils.HttpUtil;
import com.payment.utils.mail.SendMailUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.MailException;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.BufferedOutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;

@RestController
@Api(tags = "payPal支付回调")
/**
 * 1，使用领科的payPal收款账号收款payPal支付回调接口：
 *
 * 2，适用于老的客户：第一版的领科商城，Travis 这种老的客户；
 *
 * 3，更新的数据表为：user_order_payment_manager_t，user_bound_payment_order_t；
 *
 *  4，更新的数据库为：links
 *
 * @author lm
 * @date 2019/11/06
 */
@Slf4j
public class PayPalNotifyController {
    @Autowired
    private OrderPaymentManagerService orderPaymentManagerService;
    @Autowired
    private NotificationpaymentService notificationpaymentService;
    @Autowired
    PartnerService partnerService;

    /*支付方式:1-微信支付，2-payPal支付，3-oceanPay支付,4-第三方自行支付*/

    private String payType = "2";
    /**
     * 3.0接口：请求北京企业网关的地址
     */
    @Value("${jsonIot3.JSON_BASE_URL}")
    private String jsonBaseURL3;
    @Autowired
    GatewayToBeijingService toBeijingService;

    @Autowired
    JavaMailSenderImpl javaMailSender;

    /***
     * 此方法专门处理paypal的ipn回调
     * @param requestStr
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/paypalNotifyCallback")
    @CrossOrigin
    public String ipn(@RequestBody String requestStr) throws Exception {
        log.info("payPal的ipn回调是：" + requestStr);
        try {
            requestStr = URLDecoder.decode(requestStr, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        String[] firstStr = requestStr.split("&");
        Map<String, String> m = new HashMap<String, String>();
        for (int i = 0; i < firstStr.length; i++) {
            if (firstStr[i].split("=").length == 1) {
                firstStr[i] = firstStr[i] + "0000";
            }
            m.put(firstStr[i].substring(0, firstStr[i].indexOf("=")), firstStr[i].substring(firstStr[i].indexOf("=") + 1));
        }
        String orderId = m.get("invoice");
        String amount = m.get("mc_gross");
        log.info("收款账号是：" + m.get("business") + ";收款金额：" + m.get("mc_gross") + "付款状态是：" + m.get("payment_status") + ";付款订单：" + orderId);

        //将payPal回传的交易记录入库保存下来:notification_payment_results_paypal_t
        int c = notificationpaymentService.findCountByOrderNumber(m.get("invoice"));
        if (c <= 0) {
            //入库
            PaypalNotificationpaymentResults results = new PaypalNotificationpaymentResults();
            results.setMc_gross(amount);
            results.setAmount(amount);
            results.setOrderNumber(m.get("invoice"));
            results.setInvoice(m.get("invoice"));
            results.setPayment_status(m.get("payment_status"));
            results.setPaymentStatus(m.get("payment_status"));
            results.setMc_currency(m.get("mc_currency"));
            results.setMcCurrency(m.get("mc_currency"));
            results.setTxn_id(m.get("txn_id"));
            results.setTxnId(m.get("txn_id"));
            results.setProtection_eligibility(m.get("protection_eligibility"));
            results.setAddress_status(m.get("address_status"));
            results.setPayer_id(m.get("payer_id"));
            results.setAddress_street(m.get("address_street"));
            results.setPayment_date(m.get("payment_date"));
            results.setCharset(m.get("charset"));
            results.setAddress_zip(m.get("address_zip"));
            results.setFirst_name(m.get("first_name"));
            results.setMc_fee(m.get("mc_fee"));
            results.setAddress_country_code(m.get("address_country_code"));
            results.setAddress_name(m.get("address_name"));
            results.setNotify_version(m.get("notify_version"));
            results.setCustom(m.get("custom"));
            results.setPayer_status(m.get("payer_status"));
            results.setBusiness(m.get("business"));
            results.setAddress_country(m.get("address_country"));
            results.setAddress_city(m.get("address_city"));
            results.setQuantity(m.get("quantity"));
            results.setVerify_sign(m.get("verify_sign"));
            results.setPayer_email(m.get("payer_email"));
            results.setPayment_type(m.get("payment_type"));
            results.setLast_name(m.get("last_name"));
            results.setAddress_state(m.get("address_state"));
            results.setReceiver_email(m.get("receiver_email"));
            results.setPayment_fee(m.get("payment_fee"));
            results.setReceipt_id(m.get("receiver_id"));
            results.setTxn_type(m.get("txn_type"));
            results.setItem_name(m.get("item_name"));
            results.setItem_number(m.get("item_number"));
            results.setResidence_country(m.get("residence_country"));
            results.setReceipt_id(m.get("receipt_id"));
            results.setTransaction_subject(m.get("transaction_subject"));
            results.setPayment_gross(m.get("payment_gross"));
            results.setIpn_track_id(m.get("ipn_track_id"));
            notificationpaymentService.insertPaymentResultsPaypal(results);
            log.info("payPal回调信息入库完成！");
        }
        //回调的订单是成功的才要入库啊操作
        if ("Completed".equalsIgnoreCase(m.get("payment_status")) && orderId != null) {
            //查询数据库中当前这条数据插入过没有
            int count = orderPaymentManagerService.findOrderIdByNotify(orderId);
            if (count <= 0) {
                //说明当前没有插入记录 ，现在就去插入
                //支付方式：1-公众号支付，2-paypal，3-oceanpay，4-H5微信支付
                // 成功就将PayRst设为1；不插入就数据库默认0 ，成功就要通知，数据库就记1，不成功就不通知数据库会默认0
                OrderPaymentManager paymentOrder = new OrderPaymentManager();
                paymentOrder.setPayRst("success");
                paymentOrder.setIsNotify("1");
                paymentOrder.setPayType(payType);
                paymentOrder.setOrderId(orderId);
                paymentOrder.setAmount(amount);
                orderPaymentManagerService.updatePayRst(paymentOrder);
                log.info("payPal支付结果入库完成！");

                //兼容之前的记录：
                UserboundPaymentOrder order = new UserboundPaymentOrder();
                order.setPaymentOrderId(orderId);
                order.setPayType("2");
                order.setIsNotify("1");
                order.setAmount(amount);
                order.setOrderCurrency(m.get("mc_currency"));
                order.setPayRst("success");
                orderPaymentManagerService.UpdatePaypalNotify(order);
                log.info("payPal支付数据入库完成!");
                //拿到orderId就去做支付结果通知就好
                //return "forward:/payNotify?orderId=" + m.get("invoice") + "&payType=" + Constant.PAY_PAYPAL + "&payAmount=" + m.get("mc_gross") + "";

                //将去北京做支付结果通知的工作交到具体的PaymentResultService处理类中去
                OrderPaymentManager userOrder = orderPaymentManagerService.queryOrderByOrderId(orderId, amount);
                if (userOrder == null) {
                    log.info("OrderPaymentManager表中没有查询到需要去做支付结果通知的数据！");
                    UserboundPaymentOrder paymentManagerOrder = orderPaymentManagerService.queryPaymentOrderByOrderId(orderId, amount);

                    if (paymentManagerOrder == null) {
                        log.info("UserboundPaymentOrder表中没有查询到需要去做支付结果通知的数据！");
                    } else {
                        String partnerCode = paymentManagerOrder.getPartnerCode();
                        String orderCode = paymentManagerOrder.getOrderId();
                        String deviceId = paymentManagerOrder.getDeviceId();
                        String deviceType = paymentManagerOrder.getDeviceType();
                        String payAmount = paymentManagerOrder.getAmount();
                        log.info("查询到的订单orderId是:" + orderCode + ";DeviceId是:" + deviceId + ";DeviceType是:" + deviceType + ";payAmount是：" + payAmount);
                        String secret = partnerService.findSecretByPartnerCode(partnerCode);

                        RequestNotify notify = new RequestNotify();
                        notify.setDeviceId(deviceId);
                        notify.setOrderId(orderCode);
                        notify.setPayAmount(amount);
                        notify.setPayType(payType);
                        notify.setSecret(secret);
                        notify.setPartnerCode(partnerCode);
                        // 开始组装json
                        String requestStrs = JSON.toJSONString(notify);
                        log.info("请求北京的接口请求报文：" + requestStrs);
                        String url = Constant.requestURI + Constant.iot_notify;
                        // 发送post请求，并接收返回结果
                        String returnStr = HttpUtil.httpPost(url, requestStr);
                        log.info("北京回复的下发接口响应报文：" + returnStr);
                        ResponseNotify re = JSONArray.parseObject(returnStr, ResponseNotify.class);

                        if (re == null) {
                            log.info("请求直接有问题");
                        } else if (true == Constant.RET_CODE_0000.equalsIgnoreCase(re.getRetCode())) {

                            OrderPaymentManager paymentManager = new OrderPaymentManager();
                            paymentManager.setIsNotify("0");
                            paymentManager.setOrderId(orderId);
                            paymentManager.setAmount(amount);
                            orderPaymentManagerService.updateIsNotifyOrderT(paymentManager);
                            log.info("UserboundPaymentOrder数据库更新完成");

                        } else {
                            log.info("去请求遇到了问题，不管了先");

                        }
                        log.info("支付结果处理完了");
                    }
                } else {
                    String partnerCode = userOrder.getPartnerCode();
                    String orderCode = userOrder.getOrderId();
                    String deviceId = userOrder.getDeviceId();
                    String deviceType = userOrder.getDeviceType();

                    String payAmount = userOrder.getAmount();
                    log.info("查询到的订单orderId是:" + orderCode + ";DeviceId是:" + deviceId + ";DeviceType是:" + deviceType + ";payAmount是：" + payAmount);
                    String secret = partnerService.findSecretByPartnerCode(partnerCode);

                    RequestNotify notify = new RequestNotify();
                    notify.setDeviceId(deviceId);
                    notify.setOrderId(orderCode);
                    notify.setPayAmount(payAmount);
                    notify.setPayType(Constant.PAY_PAYPAL);
                    notify.setSecret(secret);
                    notify.setPartnerCode(partnerCode);
                    // 开始组装json
                    String req = JSON.toJSONString(notify);
                    log.info("请求北京的接口请求报文：" + req);
                    String url = Constant.requestURI + Constant.iot_notify;
                    // 发送post请求，并接收返回结果
                    String returnStr = HttpUtil.httpPost(url, req);
                    System.out.println("北京回复的下发接口响应报文：" + returnStr);
                    ResponseNotify re = JSONArray.parseObject(returnStr, ResponseNotify.class);

                    if (re == null) {
                        log.info("请求直接有问题");
                    } else if (true == Constant.RET_CODE_0000.equalsIgnoreCase(re.getRetCode())) {

                        OrderPaymentManager paymentManager = new OrderPaymentManager();
                        paymentManager.setIsNotify("0");
                        paymentManager.setOrderId(orderId);
                        paymentManager.setAmount(amount);
                        orderPaymentManagerService.updateIsNotify(paymentManager);
                        log.info("OrderPaymentManager数据更新完成！");

                    } else {
                        log.info("去请求遇到了问题，不管了先");

                    }
                    log.info("支付结果处理完了");
                }

            }
        } else {
            //订单状态不是完成的状态
            log.info("payment_status是多少:" + m.get("payment_status"));
        }

        return null;
    }

    /****
     * 此方法专门处理payPal的webHook回调
     * @param response
     * @param jsonRootBean
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/notifyCallback")
    @CrossOrigin
    public String webHook(HttpServletResponse response, @RequestBody JsonRootBean jsonRootBean) throws Exception {
        log.info("payPal的webHook回调是：" + JSON.toJSONString(jsonRootBean));
        if (null == jsonRootBean) {
            log.info("请求报文不合法:requestStr为空");
            return null;
        }
        if (null == jsonRootBean.getResource()) {
            log.info("请求报文不合法:resource对象不能为空");
            return null;
        }
        //Resource
        Resource resource = jsonRootBean.getResource();
        String invoiceNumber = "";
        String state = "";
        if (StringUtils.isNotBlank(resource.getInvoice_number())) {
            invoiceNumber = resource.getInvoice_number();
        }
        if (StringUtils.isNotBlank(resource.getState())) {
            state = resource.getState();
        }
        log.info("回调的订单号是：" + invoiceNumber + ";状态是：" + state);
        String id = resource.getId() + "";
        String payment_mode = resource.getPayment_mode() + "";
        String protection_eligibility = resource.getProtection_eligibility() + "";
        String protection_eligibility_type = resource.getProtection_eligibility_type() + "";
        String parent_payment = resource.getParent_payment() + "";

        Amount amount;
        String total = "";
        String currency = "";
        String subtotal = "";
        if (null != resource.getAmount()) {
            amount = resource.getAmount();
            //Amount
            if (StringUtils.isNotBlank(amount.getTotal())) {
                total = amount.getTotal();
            }
            if (StringUtils.isNotBlank(amount.getCurrency())) {
                currency = amount.getCurrency();
            }
            //Details
            if (null != amount.getDetails()) {
                Details details = amount.getDetails();
                if (StringUtils.isNotBlank(details.getSubtotal())) {
                    subtotal = details.getSubtotal();
                }
            }
        }

        //Transaction_fee
        String value = "";
        String currency1 = "";
        if (null != resource.getTransaction_fee()) {
            Transaction_fee transaction_fee = resource.getTransaction_fee();
            if (StringUtils.isNotBlank(transaction_fee.getValue())) {
                value = transaction_fee.getValue();
            }
            if (StringUtils.isNotBlank(transaction_fee.getCurrency())) {
                currency1 = transaction_fee.getCurrency();
            }
        }

        /*保证回调的webHook是成功的支付回调*/
        if (StringUtils.isNotBlank(invoiceNumber) && !invoiceNumber.substring(0, JsonConstant.CODE_TWO).equalsIgnoreCase(JsonConstant.CODE_WC) && JsonConstant.CODE_COMPLETED.equalsIgnoreCase(state)) {
            int c = notificationpaymentService.findCountByInvoiceNumber(invoiceNumber);
            if (c <= 0) {
                PaypalpaymentResults results = new PaypalpaymentResults();
                results.setPaypal_id(id);
                results.setState(state);
                results.setInvoice_number(invoiceNumber);
                results.setPayment_mode(payment_mode);
                results.setProtection_eligibility(protection_eligibility);
                results.setProtection_eligibility_type(protection_eligibility_type);
                results.setParent_payment(parent_payment);
                results.setTotal(total);
                results.setCurrency(currency);
                results.setSubtotal(subtotal);
                results.setTransaction_fee(value);
                results.setTransaction_fee_currency(currency1);
                notificationpaymentService.addPaypalpaymentResults(results);
                log.info("支付网关-payPal-webHook-的回调信息入库完成！");
            }
            /*回调的订单是成功的才要入库啊操作,查询数据库中当前这条数据插入过没有*/
            Integer count = orderPaymentManagerService.findOrderCodeByNotify(invoiceNumber);
            if (count < 1) {
                /*说明当前没有插入记录 ，现在就去插入;支付方式:1-微信支付，2-payPal支付，3-oceanPay支付,4-第三方自行支付;成功就将PayRst设为1；不插入就数据库默认0;成功就要通知，数据库就记1，不成功就不通知数据库会默认0*/
                OrderPaymentManager paymentOrder = new OrderPaymentManager();
                paymentOrder.setPayRst("success");
                paymentOrder.setIsNotify("1");
                paymentOrder.setPayType(payType);
                /*paymentOrder.setOrderId(invoiceNumber);*/
                paymentOrder.setOrderNo(invoiceNumber);
                paymentOrder.setAmount(total);
                Integer count1 = orderPaymentManagerService.updatePayRst(paymentOrder);
                if (count1 > 0) {
                    log.info("OrderPaymentManager表支付结果入库完成！");
                    /*去数据库取订单数据准备去做订购*/
                    OrderPaymentManager userOrder = orderPaymentManagerService.queryOrderByOrderNo(invoiceNumber);
                    if (null != userOrder) {
                        String secret = partnerService.findSecretByPartnerCode(userOrder.getPartnerCode());
                        /*查询正在使用的订单*/
                        ResponseQueryDeviceOrder orderQuery = toBeijingService.queryDeviceOrder(userOrder.getDeviceId(), "", "2", "", userOrder.getPartnerCode(), secret);
                        if (null != orderQuery && JsonConstant.RET_CODE_0000.equals(orderQuery.getCode()) && null != orderQuery.getData() && null != orderQuery.getData().getPackageOrder() && !orderQuery.getData().getPackageOrder().isEmpty()) {
                            for (DevicePackageOrder or : orderQuery.getData().getPackageOrder()) {
                                if (StringUtils.isNotBlank(or.getOrderId()) && JsonConstant.CODE_STRING_TWO.equals(or.getOrderStatus()) && !"DP20190513000751".equals(or.getPackageCode())) {
                                    /*开始对正在使用的订单进行提前结束*/
                                    EndResponse aheadFinish = toBeijingService.aheadEndOrder(or.getOrderId(), userOrder.getPartnerCode(), secret, "周期未结束需开启新的订单");
                                    /*成功提前结束的情况*/
                                    if (null != aheadFinish) {
                                        if (null != aheadFinish.getCode()) {
                                            if (JsonConstant.RET_CODE_0000.equals(aheadFinish.getCode())) {
                                                /*成功提前结束订单*/
                                                log.info(userOrder.getDeviceId() + ":提前结束订单：" + or.getOrderId() + "：成功！");
                                            } else {
                                                //发送异常邮件：
                                                sendMail(userOrder.getDeviceId(), userOrder.getPackageName(), or.getOrderPeriod(), userOrder.getPartnerName(), or.getOrderId(), "提前结束订单", aheadFinish.getMessage());
                                                log.info(userOrder.getDeviceId() + "：【正在使用订单】提前结束失败，原因：" + aheadFinish.getMessage());
                                            }

                                        } else {
                                            log.info(userOrder.getDeviceId() + ":提前结束订单：" + or.getOrderId() + "：失败！");
                                            /*接口响应原因导致的提前结束订单失败：发送异常邮件*/
                                            sendMail(userOrder.getDeviceId(), userOrder.getPackageName(), or.getOrderPeriod(), userOrder.getPartnerName(), or.getOrderId(), "提前结束订单", "接口连接超时或其他原因的提前结束失败");
                                            //记录异常操作到数据库：
                                            log.info(userOrder.getDeviceId() + "：【正在使用订单】因接口连接超时或其他原因提前结束失败");
                                        }
                                    } else {
                                        log.info(userOrder.getDeviceId() + ":提前结束订单：" + or.getOrderId() + "：失败！");
                                        /*接口响应原因导致的提前结束订单失败：发送异常邮件*/
                                        sendMail(userOrder.getDeviceId(), userOrder.getPackageName(), or.getOrderPeriod(), userOrder.getPartnerName(), or.getOrderId(), "提前结束订单", "接口连接超时或其他原因的提前结束失败");
                                        //记录异常操作到数据库：
                                        log.info(userOrder.getDeviceId() + "：【正在使用订单】因接口连接超时或其他原因提前结束失败");
                                    }

                                }
                            }
                        }
                        log.info("不管提前结束订单有没有执行，继续往下去做订购套餐操作");
                        /*2，取到数据为最终目的去处理订购套餐，第三方支付在去订购时候的payType赋值为0*/
                        RequestPurchaseService purchase = RequestPurchaseService.builder()
                                .secret(secret).partnerCode(userOrder.getPartnerCode()).deviceCode(userOrder.getDeviceId())
                                .packageCode(userOrder.getPackageCode()).packageName(userOrder.getPackageName()).packageType(userOrder.getPackageType())
                                .orderPeriod(userOrder.getOrderPeriod()).amount(userOrder.getAmount()).payType("0").build();
                        /*发起订购套餐*/
                        OrderResponse orderPackage = toBeijingService.order(purchase, "0");
                        /*先看接口订购套餐接口成功的情况*/
                        if (null != orderPackage && null != orderPackage.getCode() && JsonConstant.RET_CODE_0000.equals(orderPackage.getCode()) && null != orderPackage.getData() && StringUtils.isNotBlank(orderPackage.getData().getOrder_id())) {
                            /*订购套餐成功获取到orderId*/
                            log.info(userOrder.getDeviceId() + ":订购套餐：" + userOrder.getPackageName() + "：获取订单：" + orderPackage.getData().getOrder_id() + ":成功！");
                            /*现在去更新数据库的orderId字段*/
                            OrderPaymentManager order = new OrderPaymentManager();
                            order.setOrderId(orderPackage.getData().getOrder_id());
                            order.setOrderStartDate(orderPackage.getData().getOrder_start_date());
                            order.setOrderExpireDate(orderPackage.getData().getOrder_expire_date());
                            order.setOrderNo(invoiceNumber);
                            Integer cou = orderPaymentManagerService.updateOrderId(order);
                            if (cou > 0) {
                                log.info("订单号：" + orderPackage.getData().getOrder_id() + ":数据表内更新成功！");
                            } else {
                                log.info("订单号：" + orderPackage.getData().getOrder_id() + ":数据表内更新失败！");
                                /*最后拿到orderId更新数据库时失败*/
                                sendPrivateMail(invoiceNumber, "Travis订购下单", "最后拿到orderId更新数据库时失败");
                            }
                        } else {
                            /*再看接口订购套餐接口订购失败的情况*/
                            /*发送异常邮件*/
                            sendMail(userOrder.getDeviceId(), userOrder.getPackageName(), userOrder.getOrderPeriod(), userOrder.getPartnerName(), "", "订购流量套餐", "接口连接超时或其他原因导致订购失败");
                        }

                    }
                } else {
                    /*回调的数据入库失败*/
                    /*发送异常邮件*/
                    sendPrivateMail(invoiceNumber, "Travis支付结果回调", "数据回调orderNo结果入库失败");
                }

            } else {
                /*回调的订单跟数据库对不上，是不是回调有误？*/
                /*发送异常邮件*/
                sendPrivateMail(invoiceNumber, "Travis支付结果回调", "数据回调orderNo在数据库内无此记录");
            }

        }
        //已经收到了
        BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
        out.write("SUCCESS".getBytes());
        out.flush();
        out.close();

        return null;
    }

    /***
     * 发送异常邮件方法
     * 发给service@linksfield.net
     * @param deviceId
     * @param packageName
     * @param orderId
     * @param type
     * @param message
     */
    public void sendMail(String deviceId, String packageName, String orderPeriod, String partnerName, String orderId, String type, String message) {
        try {
            String sendText = "卡片iccId:" + deviceId + "\n" +
                    "套餐名称:" + packageName + "\n" +
                    "订购周期:" + orderPeriod + "\n" +
                    "企业名称:" + partnerName + "\n" +
                    "订单编码:" + orderId + "\n" +
                    "操作类型:" + type + "\n" +
                    "异常描述:" + message + "\n";
            javaMailSender.send(new SendMailUtil().sendIdentifyingCode("Travis支付结果回调订购套餐异常处理", sendText));
            log.info(orderId + ":异常邮件发送成功");

        } catch (MailException e) {
            log.info("邮件发送出现异常：" + e);
        }
    }

    /**
     * 发送异常邮件方法
     * 发给1556723929@qq.com
     *
     * @param orderNo
     * @param type
     * @param message
     */
    private void sendPrivateMail(String orderNo, String type, String message) {
        try {
            String sendText = "订单号:" + orderNo + "\n" +
                    "操作类型:" + type + "\n" +
                    "异常描述:" + message + "\n";
            javaMailSender.send(new SendMailUtil().sendIdentifyingPrivate("Travis支付结果回调订购套餐异常处理", sendText));
            log.info(orderNo + ":异常邮件发送成功");
        } catch (MailException e) {
            log.info("邮件发送出现异常：" + e);
        }
    }
}




